#!/bin/bash
IP=10.75.128.8
dir="/DATA/oracle/netdir/"
if [ ! -d ${dir} ];then
	mkdir -p ${dir}
fi
echo 1 > ${dir}ping.lock
while true
do
	data=`date +%F' '%H:%M`
	data1=`date +%F' '%H:%M:%S`
	echo "------------${data1}---------------">>${dir}ping2.log
	ping -c 10 ${IP} >>${dir}ping2.log
	sleep 5
	if [ $? -eq 1 ];then
		STAT=`cat ${dir}ping.lock`
		if [ ${STAT} -eq 1 ];then
			/bin/bash /DATA/oracle/netdir/GFweixin.sh it-arch it-arch "it-arch from PDC(xx.xx..6.150) ping 金融云(10.75.128.8)中断，请检查深信服VPN！ \n TIME:${data1}"
			echo 0 > ${dir}ping.lock
		else
			continue
		fi
	else
		STAT=`cat ${dir}ping.lock`
		if [ ${STAT} -eq 0 ];then
			/bin/bash /DATA/oracle/netdir/GFweixin.sh it-arch it-arch "it-arch from PDC(xx.xx..6.150) ping 金融云(10.75.128.8)恢复！ \n TIME:${data1}"
			echo 1 > ${dir}ping.lock
		else
			continue
		fi
	fi

	Time=`date +%F`
	TIME="${Time} 23:59"
	if [ "${data}" == "${TIME}" ];then
		mkdir ${dir}${Time} && mv ${dir}ping2.log ${dir}${Time}-ping2.log
		mv ${dir}${Time}-ping2.log ${dir}${Time}
	fi
	find ${dir} -mtime +7 -name "*-ping2.log" -exec rm -rf {} \;
done

